//
//  TrialViewCell.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/10.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "TrialViewCell.h"
#import "TrialModel.h"
#import "CommonMacro.h"
#import "UIImageView+WebCache.h"
@interface TrialViewCell ()

@property (nonatomic,strong) UILabel *shopName;
@property (nonatomic,strong) UIImageView *shopImg;
@property (nonatomic,strong) UIButton *startButton;
@property (nonatomic,strong) UIImageView *activityImg;
@property (nonatomic,strong) UILabel *enterNum;
@property (nonatomic,strong) UIImageView *lessImg;
@property (nonatomic,strong) UILabel *lessNum;
@property (nonatomic,strong) UILabel *activityName;
@property (nonatomic,strong) UILabel *oldPrice;


@end
@implementation TrialViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self addSubviews];
    }
    return self;
}

- (void)layoutSubviews {

    [self valueForSubViews];
}


// create subviews
-(void)addSubviews
{
    //1.添加背景
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30, 260)];
    bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"试用首页商品底框@2x"]];
    //    bgView.backgroundColor = [UIColor blueColor];
    [self addSubview:bgView];
    
    //公用坐标
    CGFloat labelX = 0;
    CGFloat labelY = 3;
    CGFloat labelW = SCREEN_WIDTH*0.16;
    CGFloat labelH = SCREEN_HEIGHT*0.06;
    CGFloat Marggin = 5;
    
    //2.商标图片
    self.shopImg = [[UIImageView alloc] initWithFrame:CGRectMake(labelX+Marggin, labelY, labelW, labelH)];
    [bgView addSubview:self.shopImg];
    
    //3.店名
    self.shopName = [[UILabel alloc] initWithFrame:CGRectMake(self.shopImg.frame.origin.x+self.shopImg.frame.size.width+Marggin, self.shopImg.frame.origin.y,SCREEN_WIDTH*0.5 , self.shopImg.frame.size.height*0.5)];
    self.shopName.textColor = UIColorWithRGBA(98, 98, 98, 1);
    self.shopName.font = [UIFont fontWithName:nil size:13];
    [bgView addSubview:self.shopName];
    
    //4.已参与
    self.enterNum = [[UILabel alloc] initWithFrame:CGRectMake(self.shopName.frame.origin.x, self.shopName.frame.origin.y+self.shopName.frame.size.height, self.shopName.frame.size.width, self.shopName.frame.size.height)];
    //    self.enterNum.backgroundColor = [UIColor redColor];
    self.enterNum.textColor = UIColorWithRGBA(189, 187, 189, 1);
    self.enterNum.font = [UIFont fontWithName:nil size:12];
    [bgView addSubview:self.enterNum];
    
    
    //5.小星星  收藏按钮
    self.startButton = [[UIButton alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.84, labelY+5, bgView.frame.size.width*0.1, bgView.frame.size.width*0.1)];
    [self.startButton setBackgroundImage:[UIImage imageNamed:@"未收藏@2x"] forState:UIControlStateNormal];
    //    self.startButton.backgroundColor = [UIColor redColor];
    [bgView addSubview:self.startButton];
    
    //6.大背景
    self.activityImg = [[UIImageView alloc] initWithFrame:CGRectMake(3, self.shopImg.frame.origin.y+self.shopImg.frame.size.height+15, bgView.frame.size.width-6, bgView.frame.size.height*0.55)];
    [bgView addSubview:self.activityImg];
    
    //7.1剩余
    self.lessImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.activityImg.frame.origin.x+Marggin*2, self.activityImg.frame.origin.y-6, self.shopImg.frame.size.width*0.8, self.shopImg.frame.size.height*1.6)];
    self.lessImg.image = [UIImage imageNamed:@"剩余@2x"];
    [bgView addSubview:self.lessImg];
    
    //7.2剩余数量
    self.lessNum = [[UILabel alloc] initWithFrame:CGRectMake(self.lessImg.frame.origin.x, self.lessImg.frame.origin.y+10, self.lessImg.frame.size.width, self.lessImg.frame.size.height)];
    self.lessNum.textAlignment = NSTextAlignmentCenter;
    self.lessNum.textColor = UIColorWithRGBA(255, 255, 255, 1);
    self.lessNum.font = [UIFont boldSystemFontOfSize:18];
    [bgView addSubview:self.lessNum];
    
    //8.产品名称
    self.activityName = [[UILabel alloc] initWithFrame:CGRectMake(self.activityImg.frame.origin.x+6, self.activityImg.frame.origin.y+self.activityImg.frame.size.height,bgView.frame.size.width*0.77, bgView.frame.size.width*0.16)];
    [self.activityName setAdjustsFontSizeToFitWidth:YES];
    [bgView addSubview:self.activityName];
    self.activityName.textColor = UIColorWithRGBA(59, 59, 59, 1);
        self.activityName.font = [UIFont fontWithName:nil size:16];
    
    
    //9.老价钱
    self.oldPrice = [[UILabel alloc] initWithFrame:CGRectMake(bgView.frame.size.width*0.8, self.activityName.frame.origin.y, bgView.frame.size.width*0.2, self.activityName.frame.size.height)];
    self.oldPrice.textColor = UIColorWithRGBA(234, 76, 114, 1);
        self.oldPrice.font = [UIFont fontWithName:nil size:20];
    self.oldPrice.font = [UIFont boldSystemFontOfSize:20];
    [bgView addSubview:self.oldPrice];

    
}

// assign values for subviews
- (void)valueForSubViews
{
    self.shopName.text = self.trialModel.shopName;
    //图片解析
    [self.shopImg setImageWithURL:[NSURL URLWithString:self.trialModel.shopImg]];
    [self.activityImg setImageWithURL:[NSURL URLWithString:self.trialModel.activityImg]];
    NSString *num = self.trialModel.enterNum;
    self.enterNum.text = [NSString stringWithFormat:@"以参与：%@",num];
    self.lessNum.text = self.trialModel.lessNum;
    [self.activityName setText:self.trialModel.activityName];
//    self.activityName.numberOfLines = 0;
//    [self.activityName sizeToFit];
    self.oldPrice.text = self.trialModel.oldPrice;
}
@end
